Repository navigation
Fix TopkDropoutStrategy dynamic risk sizing - #2281
Yin Li (yinli-systems) wants to merge 1 commit into
Conversation
|
Quick follow-up on scope: this is intentionally a small fix for #2276. I added a focused regression test where |
|
Closing as a duplicate in favor of the earlier #2277. It makes the same one-line hook correction and includes a full Qlib regression showing an overridden risk degree gates buys while preserving the default strategy path. There is no useful reason to keep parallel implementations open. |
Summary
Fixes #2276.
TopkDropoutStrategyexposesget_risk_degree(trade_step)so subclasses can implement dynamic market-timing / position-sizing logic, but the buy budget used the fixedself.risk_degreefield directly. This makes dynamic risk overrides ineffective for new buys.This PR routes the buy budget through
get_risk_degree(trade_step)and adds a focused regression test that keepsself.risk_degree = 0.95while overridingget_risk_degree()to return0.25; the generated buy order must use the dynamic 25% budget.Tests
PYTHONPYCACHEPREFIX=/private/tmp/qlib-pycache /usr/bin/python3 -m py_compile qlib/contrib/strategy/signal_strategy.py tests/backtest/test_topk_dropout_strategy.pygit diff --checkPYTHONPYCACHEPREFIX=/private/tmp/qlib-pycache /opt/homebrew/bin/python3.11 - <<'PY' ...isolated harness that stubs Qlib package-level imports, loadsqlib/contrib/strategy/signal_strategy.py, and verifies dynamic risk produces a 25-share order from 1000 cash at price 10Note: direct local
pytest -q tests/backtest/test_topk_dropout_strategy.pyis blocked in this unbuilt source tree by missing compiled extensions (qlib.data._libs.rolling). I attemptedsetup.py build_ext --inplace; this checkout lacks generated C++ sources and needs the project Cython build path first. The added test is a normal repository test and should run in CI after the extension build step.